﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using WebSOAPUI.Lib;
using Dapper;
using WebSOAPUI.Lib.Model;

namespace WebSOAPUI
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.HandleAJAXRequest();
        }

        protected void FormatXml()
        {
            var xml = Request.Form["xml"];
            var fxml = XmlUtils.FormatXml(xml);
            this.ResponseJSON(new { xml = fxml.ToString() });
        }

        protected void PostSOAPRequest()
        {
            //"urn:sap-com:document:sap:soap:functions:mc-style"
            //"urn:sap-com:document:sap:soap:functions:mc-style:
            var xml = Request.Form["xml"];
            var soapRequest = new SOAPRequest()
            {
                EndPoint = "http://10.63.0.20:8000/sap/bc/srt/rfc/sap/zesapws_mm001/310/zesapws_mm001/zesapws_mm001",
                Username = "hh_zhaowei",
                Password = "zhaowei8",
                SOAPAction = "\"urn:sap-com:document:sap:soap:functions:mc-style:ZESAPWS_MM001:ZesapfunMm001\"",
                SOAPData = xml
            };
            try
            {
                var ret = WebServiceUtils.PostSOAPRequest(soapRequest);
                ret = XmlUtils.FormatXml(ret);
                this.ResponseJSON(new { success = true, xml = ret });
            } catch (Exception ex)
            {
                this.ResponseJSON(new { success = false, error = ex.Message });
            }
        }

        protected void ResolveWsdl()
        {
            var xml = Request.Form["xml"];
            var wsInfo = WebServiceUtils.ResolveServiceInfo(xml);
            this.ResponseJSON(wsInfo);
        }
    }
}